package com.ygxsk.carhome.ui.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.CouponOrPackType;
import com.ygxsk.carhome.response.CouponCustomerVo;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-17  16:07
 * @Description:待核销的适配器，是做卡券主页列表的 待核销的适配器
 */
public class CardToBeReviewedAdapter extends BaseQuickAdapter<CouponCustomerVo, BaseViewHolder> {

    private int flag_jumpfrom_where;

    public CardToBeReviewedAdapter(int _flag_jumpfrom_where, int layoutResId, @Nullable List<CouponCustomerVo> data) {
        super(layoutResId, data);

        flag_jumpfrom_where = _flag_jumpfrom_where;

        addChildClickViewIds(
                R.id.roundtextViewDotobe, //审核的按钮
                R.id.imagerightinfoclicktobe);//R.id.textvieweditviewphonetobe,//电话的拨打的能力

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, CouponCustomerVo couponCustomerVo) {

        if (couponCustomerVo != null) {

//            备注:重要需求：
//            couponPackId  发放优惠券记录 增加了 礼包ID，  礼包ID >0 是属于礼包里发放的  ， 选择批量审核的批量  请求这个接口，返回 该礼包下的 待审核的优惠券  来批量审核礼包优惠券
            //卡券的名称：
            String couponName = couponCustomerVo.getCouponName();
            //核销状态 :是汉字形式的;
//            String stateItem = couponCustomerVo.getCouponStatusInfo();

            //卡券的类型 数字形式
//            int couponType = couponCustomerVo.getCouponType();

            //卡券类型 汉字形式
            String couponTypeInfo = couponCustomerVo.getCouponTypeInfo();

            //领取客户--手机号
            String phone = couponCustomerVo.getPhone();

            //findviews
            //卡券名称或者礼包 名称的左侧描述
            TextView textViewCarNameTobeDes = (TextView) baseViewHolder.getView(R.id.textviewcarnametobedes);
            //卡券的名称
            TextView textViewCarName = (TextView) baseViewHolder.getView(R.id.textviewcarnametobe);

            //左侧的图片信息，礼包和优惠券不同
            ImageView imageViewCounLeft = (ImageView) baseViewHolder.getView(R.id.imageviewcounleft);
            //最右侧的一个展示小图标查看详情的
            ImageView imageRightInfoClickTobe = (ImageView) baseViewHolder.getView(R.id.imagerightinfoclicktobe);

            //卡券类型 的整个外侧包裹
            RelativeLayout relativeLayoutCardTypeWarp = (RelativeLayout) baseViewHolder.getView(R.id.relativelayoutcardtypewarp);
            //卡券类型的文本描述
            TextView textViewCardType = (TextView) baseViewHolder.getView(R.id.textviewcardtypetobe);

            //领取客户 是手机号
            TextView textViewEditViewPhoneCarSmart = (TextView) baseViewHolder.getView(R.id.textvieweditviewphonetobe);

            //----------------------------------------------------------------------------------------------------------
            //2024-1-2 09:39:26 多个审核布局包裹,批量审核
            RoundTextView roundtextViewDoTobe = (RoundTextView) baseViewHolder.getView(R.id.roundtextViewDotobe);
            //审核按钮：
//            RoundTextView roundtextViewDoVerifyOne = (RoundTextView) baseViewHolder.getView(R.id.roundtextViewDoVerifyOne);
            //批量审核按钮
//            RoundTextView roundtextViewDoVerifyMoreItems = (RoundTextView) baseViewHolder.getView(R.id.roundtextViewDoVerifyMoreItems);
            //帮助线条，如果是最后一个线条，布局隐藏
//            TextView textViewHelpInSmartList = (TextView) baseViewHolder.getView(R.id.textviewhelpinsmartlist);
            //----------------------------------------------------------------------------------------------------------

            //卡券的名称
            CommUtils.setText(textViewCarName, couponName);

            //卡券类型
            CommUtils.setText(textViewCardType, couponTypeInfo);

            //客户手机号不是明文的?
            CommUtils.setText(textViewEditViewPhoneCarSmart, StringCodeUtils.mobileEncrypt(phone));

            //如果需要审核，那么审核按钮显示：
            //是否可以审核（权限）1是0否
            //private Integer isExamine;
            int isExamine = couponCustomerVo.getIsExamine();

            //是否是大礼包类型的，大礼包类型。 "packType": 2, //1：优惠券； 2:礼包
            int packType = couponCustomerVo.getPackType();

            if (isExamine == 0) {

                roundtextViewDoTobe.setVisibility(View.INVISIBLE);

            } else if (isExamine == 1) {

                roundtextViewDoTobe.setVisibility(View.VISIBLE);

            } else {
                roundtextViewDoTobe.setVisibility(View.INVISIBLE);
            }


            //------------------------------------------------------------
//            public enum CouponOrPackType {
//                //"packType": 2, //1：优惠券； 2:礼包
//                IS_COUPON_NOMAL(1, "优惠券"),
//                IS_COUPON_PACK(2, "礼包");

            //如果是礼包类型
            if (packType == CouponOrPackType.IS_COUPON_NOMAL.getIndex()) {

                //优惠券类型的描述文字：是卡券名称
                CommUtils.setText(textViewCarNameTobeDes, getContext().getString(R.string.smart_issue_coupon_adapter));
                //卡券类型展开
                CommUtils.setViewVisible(relativeLayoutCardTypeWarp);

                Glide.with(getContext())//
                        .load(R.drawable.icon_cardy)//
                        //.transition(withCrossFade())
                        .placeholder(R.drawable.icon_errorfang)//
                        .error(R.drawable.icon_errorfang)//
                        .fallback(R.drawable.icon_errorfang)//
                        .into(imageViewCounLeft);//

            } else if (packType == CouponOrPackType.IS_COUPON_PACK.getIndex()) {

                //优惠券类型的描述文字：是礼包名称
                CommUtils.setText(textViewCarNameTobeDes, getContext().getString(R.string.smart_issue_pack_adapter));
                //卡券类型隐藏
                CommUtils.setViewGone(relativeLayoutCardTypeWarp);

                Glide.with(getContext())//
                        .load(R.drawable.icon_cardl)//优惠券礼包类型
                        //.transition(withCrossFade())
                        .placeholder(R.drawable.icon_errorfang)//
                        .error(R.drawable.icon_errorfang)//
                        .fallback(R.drawable.icon_errorfang)//
                        .into(imageViewCounLeft);//

            }

            //------------------------------------------------------------
            //------------------------------------------------------------

        }
    }
}
